package com.ruoyi.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.StringUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MedMo;
import com.ruoyi.system.service.IMedMoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 药品-处方关联Controller
 * 
 * @author yangxp
 * @date 2020-08-06
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/medicine/medMo" )
public class MedMoController extends BaseController {

    private final IMedMoService iMedMoService;

    /**
     * 查询药品-处方关联列表
     */
    @PreAuthorize("@ss.hasPermi('medicine:medMo:list')")
    @GetMapping("/list")
    public TableDataInfo list(MedMo medMo)
    {
        startPage();
        LambdaQueryWrapper<MedMo> lqw = new LambdaQueryWrapper<MedMo>();
        List<MedMo> list = iMedMoService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出药品-处方关联列表
     */
    @PreAuthorize("@ss.hasPermi('medicine:medMo:export')" )
    @Log(title = "药品-处方关联" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(MedMo medMo) {
        LambdaQueryWrapper<MedMo> lqw = new LambdaQueryWrapper<MedMo>(medMo);
        List<MedMo> list = iMedMoService.list(lqw);
        ExcelUtil<MedMo> util = new ExcelUtil<MedMo>(MedMo. class);
        return util.exportExcel(list, "medMo" );
    }

    /**
     * 获取药品-处方关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('medicine:medMo:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iMedMoService.getById(id));
    }

    /**
     * 新增药品-处方关联
     */
    @PreAuthorize("@ss.hasPermi('medicine:medMo:add')" )
    @Log(title = "药品-处方关联" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MedMo medMo) {
        return toAjax(iMedMoService.save(medMo) ? 1 : 0);
    }

    /**
     * 修改药品-处方关联
     */
    @PreAuthorize("@ss.hasPermi('medicine:medMo:edit')" )
    @Log(title = "药品-处方关联" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MedMo medMo) {
        return toAjax(iMedMoService.updateById(medMo) ? 1 : 0);
    }

    /**
     * 删除药品-处方关联
     */
    @PreAuthorize("@ss.hasPermi('medicine:medMo:remove')" )
    @Log(title = "药品-处方关联" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iMedMoService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
